/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.client.virtual.model;

import offset.nodes.client.virtual.model.jcr.QName;
import offset.nodes.client.model.SimpleNamespaceRegistry;


public class SchemaItem {
    public static final String TYPE_NODE = "node";
    public static final String TYPE_PROPERTY = "property";

    private QName name;
    
    public SchemaItem(QName name) {
        this.name = name;
    }
    
    public QName getName() {
        return name;
    }
    
    public void setName(QName name) {
        this.name = name;
    }
    
    public String toString() {
        return toString(name);
    }
    
    public static String toString(QName name) {
        if ( name == null || name.toString().length() == 0)
            return "";
        
        if ( name.getNamespaceURI() == null )
            return name.getLocalName();
        
        String prefix = "";
        try {
            if ( SimpleNamespaceRegistry.getInstance().getPrefix(name.getNamespaceURI()) != null)
                prefix = (String) SimpleNamespaceRegistry.getInstance().getPrefix(name.getNamespaceURI());
        } catch( Exception e) {
            e.printStackTrace();
        }
        return prefix + ":" + name.getLocalName();
    }
}
